package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.admin.service.impl.AdChannelServiceImpl;
import com.usian.api.admin.AdChannelAdminApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.GET;
import java.util.List;

@RestController
@RequestMapping("/api/v1/channel/")
public class AdChannelController implements AdChannelAdminApi {
    @Autowired
    AdChannelService adChannelService;

    @RequestMapping("/list")
    @Override
    public ResponseResult findByList(@RequestBody ChannelDto dto) {
        return adChannelService.findByList(dto);
    }

    @PostMapping("/save")
    @Override
    public ResponseResult insert(@RequestBody AdChannel adChannel) {
        return adChannelService.insert(adChannel);
    }

    @PostMapping("/update")
    @Override
    public ResponseResult updates(@RequestBody AdChannel adChannel) {
        return adChannelService.updates(adChannel);
    }

    @GetMapping("/del/{id}")
    @Override
    public ResponseResult del(@PathVariable("id") Integer id) {
        return adChannelService.del(id);
    }


    /**
     * 查询所有频道
     * @return
     */
    @GetMapping("/channels")
    @Override
    public ResponseResult channel() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }



}
